<?php
include("inc/class.otr.php");
$otr = new OTR();

if(!$otr->checkLogin()){
	header("Location: index.php");
}

if(isset($_REQUEST['id'])){

	$customer_id = "*NEW*";
	$customer_company = "";
	$customer_contact = "";
	$customer_phone = "";
	$customer_email = "";
	
	if($_REQUEST['id']!=0){
		$customer = $otr->getCustomer($_REQUEST['id']);
		//print_r($project);
		$customer_id = $customer['id'];
		$customer_company = $customer['company'];
		$customer_contact = $customer['contact'];
		$customer_phone = $customer['phone'];
		$customer_email = $customer['email'];
	}
}else{
	//assume save or insert
	$res = $otr->setCustomer($_REQUEST['txt_id'], $_REQUEST['txt_company'], $_REQUEST['txt_contact'], $_REQUEST['txt_phone'], $_REQUEST['txt_email']);
	echo($res);
	exit();
	
	/*$project_id = $_REQUEST['txt_id'];
	$project_shortname = $_REQUEST['txt_shortname'];
	$project_description = $_REQUEST['txt_description'];
	$project_local = $_REQUEST['txt_local'];
	$project_site = $_REQUEST['txt_site'];
	$project_customer = $_REQUEST['ddl_customer'];
	$project_started = $_REQUEST['txt_starteddate'];
	$project_ended = $_REQUEST['txt_completeddate'];
	$project_completed = $_REQUEST['chk_completed'];*/
}
?>
<div id="customer" style="float: left;">
<form id="frm_customer" method="post" action="customer.php">
<table>
	<tr>
		<td class="label"><label for="txt_id">id:</label></td>
		<td><input id="txt_id" name="txt_id" type="text" readonly="readonly" value="<?php echo($customer_id);?>" /></td>
	</tr>
	<tr>
		<td class="label"><label for="txt_company">company:</label></td>
		<td><input type="text" id="txt_company" name="txt_company" value="<?php echo($customer_company);?>" /></td>
	</tr>
	<tr>
		<td class="label"><label for="txt_contact">contact:</label></td>
		<td><input type="text" id="txt_contact" name="txt_contact" value="<?php echo($customer_contact);?>" /></td>
	</tr>
	<tr>
		<td class="label"><label for="txt_phone">phone:</label></td>
		<td><input type="text" id="txt_phone" name="txt_phone" value="<?php echo($customer_phone);?>" /></td>
	</tr>
	<tr>
		<td class="label"><label for="txt_email">email:</label></td>
		<td><input type="text" id="txt_email" name="txt_email" value="<?php echo($customer_email);?>" /></td>
	</tr>
	<tr>
		<td></td>
		<td>
			<input type="button" value="save" onclick="saveCustomer();"/>
		</td>
	</tr>
	<tr>
		<td></td>
		<td>
			<div id="pnl_result"></div>
		</td>
	</tr>
</table>
</form>
</div>
<script type="text/javascript">
	var saveCustomer = function(){
		ajaxPost($('frm_customer'), "customer.php", $('pnl_result'), null);
	}
</script>